<?php
namespace App\DBs;

use Illuminate\Support\Facades\DB;

class UploadDB extends BaseDB
{
    /**
     * 上传
     */

    public $tUpload = 'upload';

    public function __construct()
    {
    }

    /**
     * 新增
     */
    public function setAdd($wx,$link,$cover,$vw,$vh,$delay)
    {
        //return [$link,$vw,$vh];
        //开启事务
        DB::beginTransaction();
        try {
            $resDb = DB::table($this->tUpload)->insertGetId([
                'wx'=>$wx,'cover'=>$cover,'link'=>$link,
                'vw'=>$vw,'vh'=>$vh,'delay'=>$delay,'addTime'=>time(),
            ]);
            if (!$resDb) { return array('code'=>'-2','msg'=>'操作失败'); }
            //提交事务
            DB::commit();
            return array('code'=>'0', 'msg'=>'操作成功');
        } catch (\Exception $e) {
            //事务回滚
            DB::rollBack();
            return array('code'=>'-1', 'msg'=>'操作失败：'.$e);
        }
    }
}